package com.ft.oa.web.development;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.oa.domain.dev.WeeklyReport;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.service.development.WeeklyReportService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 项目周报日报
 */
@RestController
@RequestMapping("/weekly/report")
public class WeeklyReportController {

    @Resource
    private WeeklyReportService weeklyReportService;

    /**
     * 填写或编辑日报
     * @param weeklyReport
     * @return
     */
    @PostMapping("/save")
    public ApiResult saveWeeklyReport (@RequestBody List<WeeklyReport> weeklyReport) throws Exception {
        ApiResult apiResult = weeklyReportService.addWeeklyReport(weeklyReport);
        return apiResult;
    }

    @PostMapping("/update")
    public ApiResult updateWeeklyReport (@RequestBody List<WeeklyReport> weeklyReport){
        ApiResult apiResult = weeklyReportService.updateWeeklyReport(weeklyReport);
        return apiResult;
    }

    @PostMapping("/delete")
    public ApiResult deleteWeeklyReport(@RequestBody List<WeeklyReport> weeklyReport){
        ApiResult apiResult = weeklyReportService.deleteWeeklyReport(weeklyReport);
        return apiResult;
    }

    @PostMapping("/fillReportPrepare")
    public ApiResult fillReportPrepare() throws Exception {
        Map<String, Object> result = weeklyReportService.fillReportPrepare();
        return ApiResult.successWithData(result);
    }

    @PostMapping("/pageQueryReport")
    public ApiResult pageQueryReport(@RequestBody WeeklyReport weeklyReport){
        Page<WeeklyReport> page = weeklyReportService.pageQueryReport(weeklyReport);
        return ApiResult.successWithData(page);
    }
}
